<template>
  <a-modal
    :title="title"
    :width="width"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭">
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">
        <a-tabs defaultActiveKey="1" @change="callback">
          <a-tab-pane tab="审批" key="1">
            <!--<a-form-item label="流程" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="[ 'processId', validatorRules.processId]" placeholder="请输入流程"></a-input>
            </a-form-item>-->
            <!--          0_贫困户贷款，1_企业贷款，2_带贫企业认定，3_带贫合作社认定-->
            <a-form-item label="流程类别" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <j-dict-select-tag :disabled="isEdit" type="list" v-decorator="['approvalProcessType']"
                                 :trigger-change="true" dictCode="approval_process_type" placeholder="请选择流程类别"/>
            </a-form-item>

            <a-form-item label="流程步骤" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <j-dict-select-tag :disabled="isEdit" type="list" v-decorator="['approvalProcessCode']"
                                 :trigger-change="true" dictCode="current_status_pkh" placeholder="请选择流程节点"/>
              <!--               <a-input v-decorator="[ 'approvalProcessCode', validatorRules.approvalProcessCode]" placeholder="请输入流程步骤"></a-input>-->
            </a-form-item>
            <a-form-item label="受理人" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="[ 'operator', validatorRules.operator]"
                       placeholder="请输入受理人"></a-input>
            </a-form-item>
            <!--<a-form-item label="受理日期" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <j-date placeholder="请选择受理日期" v-decorator="[ 'approvalProcessDate', validatorRules.approvalProcessDate]" :trigger-change="true" style="width: 100%"/>
            </a-form-item>-->
            <a-form-item label="回复内容" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-textarea v-decorator="['replyContent',validatorRules.replyContent]" rows="4" placeholder="请输入回复内容"/>
            </a-form-item>
            <a-form-item label="相关资料" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <j-upload-img v-decorator="['information', validatorRules.information]"
                            :trigger-change="true"></j-upload-img>
            </a-form-item>
            <!--        0_通过，1_拒绝-->
            <a-form-item label="状态" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <j-dict-select-tag :disabled="isEdit" type="list" v-decorator="['state',validatorRules.state]"
                                 :trigger-change="true"
                                 dictCode="process_state"
                                 placeholder="请选择状态"/>
            </a-form-item>
            <div style="text-align: center" v-if="isShowGongShi">
              <a @click="gongShi()">
                <a-button type="primary" icon="plus">添加数据到公示台账</a-button>
              </a>
            </div>
            <div style="text-align: center" v-if="isShowTuiJian">
              <a @click="tuiJian()">
                <a-button type="primary" icon="plus">添加数据到推荐台账</a-button>
              </a>
            </div>
            <div style="text-align: center" v-if="isShowFangKuan">
              <a @click="fangKuan()">
                <a-button type="primary" icon="plus">添加数据到放款台账</a-button>
              </a>
            </div>
          </a-tab-pane>
          <!-- <a-tab-pane tab="流程" key="2" forceRender>
             <img src="../../../../assets/pkh_process.png" alt="logo">
           </a-tab-pane>-->
        </a-tabs>
      </a-form>
    </a-spin>
    <SmallAmountPublicityAccountModal ref="smallAmountPublicityAccountModal"></SmallAmountPublicityAccountModal>
    <SmallLoanAccountModal ref="smallLoanAccountModal"></SmallLoanAccountModal>
    <SmallRecommendationAccountModal ref="smallRecommendationAccountModal"></SmallRecommendationAccountModal>
  </a-modal>
</template>

<script>

    import {httpAction, getAction} from '@/api/manage'
    import pick from 'lodash.pick'
    import JDate from '@/components/jeecg/JDate'
    import JUpload from '@/components/jeecg/JUpload'
    import JDictSelectTag from "@/components/dict/JDictSelectTag"
    import SmallAmountPublicityAccountModal from "../SmallAmountPublicityAccountModal";
    import SmallLoanAccountModal from "../SmallLoanAccountModal";
    import SmallRecommendationAccountModal from "../SmallRecommendationAccountModal";
    import JUploadImg from "../../../../../components/jeecg/JUploadImg";

    export default {
        name: "ProcessingModal1",
        components: {
            JUploadImg,
            JDate,
            JUpload,
            JDictSelectTag,
            SmallRecommendationAccountModal,
            SmallLoanAccountModal,
            SmallAmountPublicityAccountModal,
        },
        data() {
            return {
                isShowGongShi: false,
                isShowTuiJian: false,
                isShowFangKuan: false,
                isEdit: true,
                form: this.$form.createForm(this),
                title: "审批",
                width: 800,
                visible: false,
                model: {},
                labelCol: {
                    xs: {span: 24},
                    sm: {span: 5},
                },
                wrapperCol: {
                    xs: {span: 24},
                    sm: {span: 16},
                },

                confirmLoading: false,
                validatorRules: {
                    processId: {},
                    approvalProcessType: {},
                    approvalProcessCode: {},
                    approvalProcessDate: {},
                    information: {},
                    operator: {rules: [{required: true, message: '受理人不能为空'}]},
                    replyContent: {rules: [{required: true, message: '回复内容不能为空'}]},
                    state: {rules: [{required: true, message: '状态不能为空'}]},
                },
                url: {
                    add: "/loanmanagement/processing/add",
                    edit: "/loanmanagement/processing/edit",
                    judgeAuditState: "/loanmanagement/processing/queryByProcessId",
                }
            }
        },
        created() {
        },
        methods: {
            gongShi() {
                var processId = this.model.processId;
                this.$refs.smallAmountPublicityAccountModal.showGoodsGallery1(processId);
            },
            tuiJian() {
                var processId = this.model.processId;
                this.$refs.smallRecommendationAccountModal.showGoodsGallery1(processId);
            },
            fangKuan() {
                var processId = this.model.processId;
                this.$refs.smallLoanAccountModal.showGoodsGallery1(processId);
            },
            callback(key) {
                console.log(key);
            },
            add() {

                this.edit({});
            },
            setTitle(res) {
                if (res.approvalProcessCode != 'false') {
                    if (res.approvalProcessCode == '3') {
                        this.isShowGongShi = true;
                        this.isShowTuiJian = false;
                        this.isShowFangKuan = false;
                    } else if (res.approvalProcessCode == '4') {
                        this.isShowGongShi = false;
                        this.isShowTuiJian = true;
                        this.isShowFangKuan = false;
                    } else if (res.approvalProcessCode == '7') {
                        this.isShowGongShi = false;
                        this.isShowTuiJian = false;
                        this.isShowFangKuan = true;
                    } else {
                        this.isShowGongShi = false;
                        this.isShowTuiJian = false;
                        this.isShowFangKuan = false;
                    }
                }
            },
            edit(record) {
                this.setTitle(record);
                this.form.resetFields();
                this.model = Object.assign({}, record);
                this.visible = true;
                this.$nextTick(() => {
                    this.form.setFieldsValue(pick(this.model, 'processId', 'approvalProcessType', 'approvalProcessCode', 'approvalProcessDate', 'operator', 'replyContent', 'information', 'state'))
                })
            },
            close() {
                this.$emit('close');
                this.visible = false;
            },
            handleOk() {
                const that = this;
                // if (this.pass) {
                // 触发表单验证
                this.form.validateFields((err, values) => {
                    if (!err) {
                        that.confirmLoading = true;
                        let httpurl = '';
                        let method = '';
                        if (!this.model.id) {
                            httpurl += this.url.add;
                            method = 'post';
                        } else {
                            httpurl += this.url.edit;
                            method = 'put';
                        }
                        let formData = Object.assign(this.model, values);
                        console.log("表单提交数据", formData)
                        httpAction(httpurl, formData, method).then((res) => {
                            if (res.success) {
                                that.$message.success(res.message);
                                that.$emit('ok');
                            } else {
                                that.$message.warning(res.message);
                            }
                        }).finally(() => {
                            that.confirmLoading = false;
                            that.close();

                            this.$emit('parentComponentReLoad', 'AA')
                        })
                    }
                })
                /* } else {
                     that.$message.warning("内容不允许编辑");
                     that.close();
                 }*/
                that.close();
            },
            handleCancel() {
                this.close();
            },
            popupCallback(row) {
                this.form.setFieldsValue(pick(row, 'processId', 'approvalProcessType', 'approvalProcessCode', 'approvalProcessDate', 'operator', 'replyContent', 'information', 'state'))
            },
        }
    }
</script>